package fr.fermat.databaseManager;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;

public class DatabaseHandler extends SQLiteOpenHelper {
	public static final String ARTIST = "artist";
	public static final String TRACK = "track";
	public static final String ALBUM = "album";
	public static final String LYRIC = "lyric";

	public static final String LYRICS_TABLE_NAME = "lyrics";
	public static final String LYRICS_TABLE_CREATE = "CREATE TABLE "
			+ LYRICS_TABLE_NAME + " (" + ARTIST + " VARCHAR(30) NOT NULL , "
			+ TRACK + " VARCHAR(30) NOT NULL, " + ALBUM
			+ " VARCHAR(30) NOT NULL, " + LYRIC + " LONG TEXT, PRIMARY KEY (" + ARTIST
			+ ", " + TRACK + "));";

	public static final String LYRICS_TABLE_DROP = "DROP TABLE IF EXISTS "
			+ LYRICS_TABLE_NAME + ";";

	public DatabaseHandler(Context context, String name, CursorFactory factory,
			int version) {
		super(context, context.getExternalFilesDir(null).getAbsolutePath() + "/" +name, factory, version);
	}

	@Override
	public void onCreate(SQLiteDatabase db) {
		db.execSQL(LYRICS_TABLE_CREATE);
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int arg1, int arg2) {
		db.execSQL(LYRICS_TABLE_DROP);
		onCreate(db);
	}
}
